package graphics.raytracing;

import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import static util.MatrixOperationsF.ar;

import org.junit.Test;

import util.MatrixOperationsF;
public class _TriangleTest {
	class TestRay implements Ray
	{
		private float[] _origin;
		private float[] _direction;
		public TestRay(float[] origin ,float[] direction) {
		_origin=origin;_direction=MatrixOperationsF.normalize(direction);
		}
		@Override
		public void castOn(Tracable trace, Window window) {}
		@Override
		public boolean canBeCast() {return false;}
		@Override
		public float[] getOrigin() {return _origin;}
		@Override
		public float[] getDirection() {	return _direction;}
	}
	@Test
	public void testHit()
	{
		float[][] tri = new float[3][];
		tri[0]=ar(0,0,0,1);
		tri[1]=ar(10,0,0,1);
		tri[2]=ar(0,10,0,1);
		Triangle t = new Triangle(tri);
		Ray ray = new TestRay(ar(1,1,1,1),ar(0,0,-5,1));
		float[] bgt=t.determine_hit_location(ray);
		assertTrue(bgt[2]==1);
		assertTrue(bgt[0]<1&&bgt[0]>0);
		assertTrue(bgt[1]<1&&bgt[1]>0);	
	}
	@Test
	public void testNoHit()
	{
		float[][] tri = new float[3][];
		tri[0]=ar(0,0,0,1);
		tri[1]=ar(10,0,0,1);
		tri[2]=ar(0,10,0,1);
		Triangle t = new Triangle(tri);
		Ray ray = new TestRay(ar(10,10,1,1),ar(0,0,-1,1));
		float[] bgt=t.determine_hit_location(ray);
		assertFalse(bgt[0]<1&&bgt[0]>0);
		assertFalse(bgt[1]<1&&bgt[1]>0);
		
	}
}
